//获取应用实例
const app = getApp();
// 引入AES.js
var baseJs = require("../../common/base.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // imgUrl: baseJs.imgUrl,
    // 上拉加载
    allGoodsData: [],
    pageIndex: 1,
    state: "",
    // 
    // userType: "",
    GTID:"",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      // userType: wx.getStorageSync('userType'),
      GTID:options.id
    })
    this.GetGoodsListByType();
    wx.setNavigationBarTitle({
      title: options.title,
    })
  },


  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.data.pageIndex++;
    this.GetGoodsListByType();
  },

  // 
  GetGoodsListByType() {
    var that = this
    wx.showLoading({
      title: '加载中',
      icon: 'success',
    })
    var that = this;
    var allGoodsData = this.data.allGoodsData;
    var pageIndex = this.data.pageIndex;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetGoodsByTypeID&GTID="+that.data.GTID+"&City=&Area=&PageIndex=" + pageIndex + "&PageSize=10&OrderBy=SaleNumber&FromType=0&SJID=0&IsAsc=false"),
      success: function (res) {
        console.log(JSON.parse(baseJs.decryUrl(res.data)));
        var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        for (var i = 0; i < json.length; i++) {
          allGoodsData.push(json[i])
        }
        that.setData({
          allGoodsData: allGoodsData,
        })
        console.log(allGoodsData);
        if (json.length == 10) {
          that.setData({
            state: 'loadMore',
          })
        } else if (json.length == 0 && pageIndex == 1) {
          that.setData({
            state: 'noData',
          })
        } else if (json.length < 10) {
          that.setData({
            state: 'noMore',
          })
        } else if (json.length == 0 && pageIndex > 1) {
          that.setData({
            state: 'noMore',
          })
        }
        wx.hideLoading();
      },
      fail: err => {
        console.log(err);
      }
    })
  },
})